var util = require('../../../../util/util.js');
var app = getApp();
Page({
  data: {
    showType: 2
  },
  orderList: [],
  onLoad: function(options) {
    // 页面初始化 options为页面跳转所带来的参数
    let that = this
    try {
      var tab = wx.getStorageSync('tab');

      this.setData({
        showType: tab
      });
    } catch (e) {}

  },

  onPullDownRefresh() {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.getOrderList();
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },

  getOrderList() {
    let that = this;
    var orderListUrl = app.globalData.apiBase + app.globalData.orderListUrl;
    util.request(orderListUrl, {
      showType: that.data.showType
    }).then(function(res) {
      console.log(res);
      if(res.retCode==-1){
        try {
          wx.removeStorageSync('userInfo');
          wx.removeStorageSync('token');
        } catch (e) {
          // Do something when catch error
        }
        wx.navigateTo({
          url: "/page/auth/login/login"
        });
      }
      that.setData({
        orderList: res
      });
    });
  },
  switchTab: function(event) {
    let showType = event.currentTarget.dataset.index;
    if(showType==null){
      showType=2;
    }
    this.setData({
      showType: showType
    });
    this.getOrderList();
  },
  onReady: function() {
    // 页面渲染完成
  },
  onShow: function() {
    // 页面显示
    this.getOrderList();
  },
  onHide: function() {
    // 页面隐藏
  },
  onUnload: function() {
    // 页面关闭
  }
})